//
//  ScheduleEditViewContrllerViewController.m
//  EpointFrame5
//
//  Created by Pill Gong on 14-2-19.
//  Copyright (c) 2014年 Epoint. All rights reserved.
//

#import "ScheduleEditViewContrllerViewController.h"
#import "ScheduleInfo.h"
#import "PGTimeView.h"
#import "UIView+Addtions.h"
#import "UIPlaceHolderTextView.h"
#import "SelectedDateViewController.h"
#import "EpointDateUtils.h"
#import "EpointStringUtil.h"
#import "DBFrameService.h"
#import "Schedule_Add_Task.h"
#import "Schedule_Update_Task.h"
#import "EpointScheduleViewController.h"

#define ScheduleAddTaskId 1
#define ScheduleUpdateTaskId 2

@interface ScheduleEditViewContrllerViewController () <PGTimeViewDelegate, UITextFieldDelegate, UITextViewDelegate>

@property (nonatomic, strong) UIScrollView *contentView;

@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UITextField *SubjectTF;
@property (nonatomic, strong) UITextField *addressTF;

@property (nonatomic, strong) UIView *timeView;
@property (nonatomic, strong) PGTimeView *startTime;
@property (nonatomic, strong) PGTimeView *endTime;

@property (nonatomic, strong) UIView *selectView;
@property (nonatomic, strong) UISwitch *msgSwitch;
@property (nonatomic, strong) UISegmentedControl *importCtrl;
@property (nonatomic, strong) PGTimeView *sendTime;
@property (nonatomic, strong) UIView *hideView;
@property (nonatomic, strong) UITextField* phoneTf;

@property (nonatomic, strong) UIView *bottomView;
@property (nonatomic, strong) UIPlaceHolderTextView *textView;

@property (nonatomic, strong) UIButton *keyboardBtn;

@end

@implementation ScheduleEditViewContrllerViewController {
    ScheduleInfo *scheduleInfo;
    CGFloat keyboardHeight;
    NSDate *itemDate;
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    scheduleInfo = [initParam valueForKey:@"scheduleInfo"];
    itemDate = [initParam valueForKey:@"itemDate"];
    if (scheduleInfo == nil) {
        self.title = @"新增日程";
    } else {
        self.title = @"日程详情";
    }
    [self setRightBarButtonItemWithTitle:@"保存" action:@selector(save:)];

    [self addContentView];
}

- (void)save:(id)sender {
    
    if ([self checkValues] == NO) {
        return;
    }
    
    NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:5];
    [params setObject:_SubjectTF.text forKey:@"Subject"];
    
    NSString *Location = @"";
    if ([EpointStringUtil stringIsNotNull:_addressTF.text]) {
        Location = _addressTF.text;
    }
    [params setObject:Location forKey:@"Location"];

    NSString *Importance = [NSString stringWithFormat:@"%d", _importCtrl.selectedSegmentIndex];
    [params setObject:Importance forKey:@"Importance"];

    NSString *ActivityDescription = @"";
    if ([EpointStringUtil stringIsNotNull:_textView.text]) {
        ActivityDescription = _textView.text;
    }
    [params setObject:ActivityDescription forKey:@"ActivityDescription"];

    NSString *FromDateTime = [EpointDateUtils convertDate2FormatYMDHMStr:_startTime.timeDate];
    [params setObject:FromDateTime forKey:@"FromDateTime"];
    
    NSString *ToDateTime = [EpointDateUtils convertDate2FormatYMDHMStr:_endTime.timeDate];
    [params setObject:ToDateTime forKey:@"ToDateTime"];
    
    NSString *ReceivePhone = [DBFrameService getUserPhontNumber];
    if (![EpointStringUtil stringIsNotNull:ReceivePhone]) {
        ReceivePhone = _phoneTf.text;
    }
    [params setObject:ReceivePhone forKey:@"ReceivePhone"];
    
    NSString *SendTime = [EpointDateUtils convertDate2FormatYMDHMStr:_sendTime.timeDate];
    [params setObject:SendTime forKey:@"SendTime"];

    [params setObject:_msgSwitch.on?@"1":@"0" forKey:@"IFNotice"];
    
    if (scheduleInfo == nil) {
        NSLog(@"save");
        [self startTask:@"Schedule_Add_Task" withParams:params withTaskId:ScheduleAddTaskId];
    } else {
        NSLog(@"edit");
        [params setObject:scheduleInfo.TXMobile forKey:@"ReceivePhone"];
        [params setObject:scheduleInfo.ActivityID forKey:@"ActivityID"];
        [self startTask:@"Schedule_Update_Task" withParams:params withTaskId:ScheduleUpdateTaskId];
    }
}

- (BOOL)checkValues {
    if (![EpointStringUtil stringIsNotNull:_SubjectTF.text]) {
        [self toastMessage:@"主题不能为空！"];
        [_SubjectTF becomeFirstResponder];
        return NO;
    }
    //获取当前时间
    NSDate * nowDate = [[NSDate alloc] init];
    NSDate*earlierDate =[_startTime.timeDate earlierDate:nowDate];
    if ([earlierDate isEqualToDate:_startTime.timeDate]) {
        [self toastMessage:@"开始时间必须大于当天时间"];
         return NO;
    }
    earlierDate =[_startTime.timeDate earlierDate:_endTime.timeDate];
    if ([earlierDate isEqualToDate:_endTime.timeDate]) {
        [self toastMessage:@"结束时间必须大于开始时间"];
         return NO;
    }
    earlierDate =[_sendTime.timeDate earlierDate:nowDate];
    if ([earlierDate isEqualToDate:_sendTime.timeDate]&&[self.msgSwitch isOn]) {
        [self toastMessage:@"短信提醒时间必须大于当天时间"];
         return NO;
    }
    return YES;
}

#pragma mark - subview

- (void)addContentView {
    self.contentView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, AppWidth, AppHeight-SystemTakeHeight)];
    _contentView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    [self.view addSubview:_contentView];
    
    [self addSubviews];
    [self addKeyboardNotification];
    [self updateStatusAndDate];
}

- (void)addSubviews {
    [self addTopView];
    [self addTimeView];
    [self addSelectView];
    [self addBottomView];
    if (!CurrentDeviceISiPad) {
        [self addKeyboardBtn];
    }
    _contentView.contentSize = CGSizeMake(AppWidth, _bottomView.bottom+TopPadding+CellHeight);
}

- (void)addTopView {
    self.topView = [[UIView alloc] initWithFrame:CGRectMake(LeftPadding, TopPadding, CellWidth, CellHeight*2)];
    [self addViewStyle:_topView];
    [_contentView addSubview:_topView];
    
    UILabel *title = [self getLeftLabel:@"主题"];
    title.centerY = CellHeight*0.5;
    [_topView addSubview:title];
    
    self.SubjectTF = [[UITextField alloc] initWithFrame:CGRectMake(LeftItemWidth, 0, CellWidth-LeftItemWidth-ItemMargin, 21)];
    _SubjectTF.placeholder = @"请输入主题";
    _SubjectTF.centerY = CellHeight*0.5;
    _SubjectTF.delegate = self;
    [_topView addSubview:_SubjectTF];
    
    
    UIImageView *line = [self getHorizontalLine:CellHeight];
    [_topView addSubview:line];
    
    
    UILabel *addressLB = [self getLeftLabel:@"地点"];
    addressLB.centerY = CellHeight*1.5;
    [_topView addSubview:addressLB];
    
    self.addressTF = [[UITextField alloc] initWithFrame:CGRectMake(LeftItemWidth, CellHeight, CellWidth-LeftItemWidth-ItemMargin, 21)];
    _addressTF.placeholder = @"请输入地点";
    _addressTF.centerY = CellHeight*1.5;
    _addressTF.delegate = self;
    [_topView addSubview:_addressTF];
}

- (void)addTimeView {
    
    self.timeView = [[UIView alloc] initWithFrame:CGRectMake(LeftPadding, TopPadding, CellWidth, CellHeight*2)];
    _timeView.top = _topView.bottom + TopPadding;
    [self addViewStyle:_timeView];
    [_contentView addSubview:_timeView];
    
    UILabel *startLB = [self getLeftLabel:@"起始"];
    startLB.centerY = CellHeight*0.5;
    [_timeView addSubview:startLB];
    
    self.startTime = [[PGTimeView alloc] initWithFrame:CGRectMake(LeftItemWidth, 0, CellWidth-LeftItemWidth, CellHeight)];
    _startTime.timeDate = [NSDate date];
    _startTime.tag = StartTimeViewTAG;
    _startTime.delegate = self;
    [_timeView addSubview:_startTime];
    
    
    UIImageView *line = [self getHorizontalLine:CellHeight];
    [_timeView addSubview:line];
    
    
    UILabel *endLB = [self getLeftLabel:@"结束"];
    endLB.centerY = CellHeight*1.5;
    [_timeView addSubview:endLB];
    
    self.endTime = [[PGTimeView alloc] initWithFrame:CGRectMake(LeftItemWidth, CellHeight, CellWidth-LeftItemWidth, CellHeight)];
    _endTime.timeDate = [NSDate date];
    _endTime.tag = EndTimeViewTAG;
    _endTime.delegate = self;
    [_timeView addSubview:_endTime];
}

- (void)addSelectView {
    self.selectView = [UIView.alloc initWithFrame:CGRectMake(LeftPadding, TopPadding, CellWidth, CellHeight*2)];
    _selectView.clipsToBounds = YES;
    _selectView.top = _timeView.bottom + TopPadding;
    [self addViewStyle:_selectView];
    [_contentView addSubview:_selectView];
    
    UILabel *endLB = [self getLeftLabel:@"重要性"];
    endLB.centerY = CellHeight*0.5;
    endLB.left = 9;
    [_selectView addSubview:endLB];
    
    self.importCtrl = [[UISegmentedControl alloc] initWithFrame:CGRectMake(60, 0, 180, 25)];
    [_importCtrl insertSegmentWithTitle:@"低" atIndex:0 animated:YES];
    [_importCtrl insertSegmentWithTitle:@"无" atIndex:1 animated:YES];
    [_importCtrl insertSegmentWithTitle:@"高" atIndex:2 animated:YES];
    _importCtrl.centerY = CellHeight*0.5;
    _importCtrl.centerX = (CellWidth + LeftItemWidth)*0.5;
    _importCtrl.selectedSegmentIndex = 1;
    _importCtrl.tintColor = MainTinColor;
    [_selectView addSubview:_importCtrl];
    
    
    self.hideView = [UIView.alloc initWithFrame:CGRectMake(0, CellHeight, CellWidth, CellHeight*2)];
    [_selectView addSubview:_hideView];
    
    UIImageView *line2 = [self getHorizontalLine:0];
    [_hideView addSubview:line2];
    
    //提醒号码view
    UILabel *phoneLB = [self getLeftLabel:@"电话"];
    phoneLB.centerY = CellHeight*0.5;
    [_hideView addSubview:phoneLB];
    _phoneTf= [[UITextField alloc] initWithFrame:CGRectMake(LeftItemWidth, 0, CellWidth-LeftItemWidth-5, CellHeight)];
    _phoneTf.textAlignment = NSTextAlignmentRight;
     [_hideView addSubview:_phoneTf];
   
    NSString *ReceivePhone = [DBFrameService getUserPhontNumber];
    _phoneTf.text = ReceivePhone;
    
    UIImageView *line3 = [self getHorizontalLine:0];
    [_hideView addSubview:line3];
    
    UILabel *sendLB = [self getLeftLabel:@"提醒"];
    sendLB.centerY = CellHeight*1.5;
    [_hideView addSubview:sendLB];
    
    self.sendTime = [[PGTimeView alloc] initWithFrame:CGRectMake(LeftItemWidth, CellHeight, CellWidth-LeftItemWidth, CellHeight)];
    _sendTime.timeDate = [NSDate date];
    _sendTime.tag = SendTimeViewTAG;
    _sendTime.delegate = self;
    [_hideView addSubview:_sendTime];

    
    UIView *secondView = [[UIView alloc] initWithFrame:CGRectMake(0, CellHeight, CellWidth, CellHeight)];
    secondView.backgroundColor = [UIColor whiteColor];
    [_selectView addSubview:secondView];
    
    UIImageView *line1 = [self getHorizontalLine:0];
    [secondView addSubview:line1];
    
    UILabel *msgLB = [self getLeftLabel:@"短信"];
    msgLB.centerY = CellHeight*0.5;
//    msgLB.left = 12;
    [secondView addSubview:msgLB];
    
    self.msgSwitch = [[UISwitch alloc] init];
    _msgSwitch.tintColor = MainTinColor;
    _msgSwitch.onTintColor = MainTinColor;
    _msgSwitch.centerY = CellHeight*0.5;
    _msgSwitch.right = CellWidth - LeftPadding;
    [_msgSwitch addTarget:self action:@selector(msgSwitchValueChanged:) forControlEvents:UIControlEventValueChanged];
    [secondView addSubview:_msgSwitch];

}

- (void)addBottomView {

    self.bottomView = [[UIView alloc] initWithFrame:CGRectMake(LeftPadding, TopPadding, CellWidth, CellHeight*4)];
    _bottomView.top = _selectView.bottom + TopPadding;
    [self addViewStyle:_bottomView];
    [_contentView addSubview:_bottomView];

    UILabel *contentLabel = [self getLeftLabel:@"内容"];
    contentLabel.centerY = CellHeight*0.5;
    [_bottomView addSubview:contentLabel];
    
    UIImageView *line = [self getHorizontalLine:CellHeight];
    [_bottomView addSubview:line];
    
    self.textView = [[UIPlaceHolderTextView alloc] initWithFrame:CGRectMake(ItemMargin, CellHeight+ItemMargin, CellWidth-ItemMargin*2, CellHeight*3-ItemMargin*2)];
    _textView.font = [UIFont systemFontOfSize:17.0];
    _textView.placeholder = @"输入内容";
    _textView.delegate = self;
    [_bottomView addSubview:_textView];
}

- (void)addKeyboardBtn {
    self.keyboardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_keyboardBtn setImage:[UIImage imageNamed:@"keyboard_blue"] forState:UIControlStateNormal];
    [_keyboardBtn setImage:[UIImage imageNamed:@"keyboard_lightblue"] forState:UIControlStateHighlighted];
    [_keyboardBtn setFrame:CGRectMake(AppWidth - 42 -5, AppHeight-SystemTakeHeight-23-5, 42, 23)];
    //    [self setKeyboardBtnHidden:NO];
    [_keyboardBtn addTarget:self action:@selector(keyboardBtnPressed) forControlEvents:UIControlEventTouchUpInside];
    _keyboardBtn.hidden = YES;
    [self.view addSubview:_keyboardBtn];
}

- (void)keyboardBtnPressed {
    _keyboardBtn.alpha = 1.0;
    [_textView resignFirstResponder];
    [self setKeyboardBtnHidden:YES];
}

- (void)setKeyboardBtnHidden:(BOOL)animated {
    _keyboardBtn.hidden = animated;
    _keyboardBtn.alpha = 1.0;
//    if (!animated) {
//        [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(fadeKeyboardBtnAlpch:) userInfo:nil repeats:NO];
//    }
}

- (void)fadeKeyboardBtnAlpch:(NSTimer *)timer {
    [timer invalidate];
    timer = nil;
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:1.0f];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    _keyboardBtn.alpha = 0.2;
    [UIView commitAnimations];
}

- (void)addViewStyle:(UIView *)view {
    view.backgroundColor = [UIColor whiteColor];
    view.layer.cornerRadius = 10;
    view.layer.borderWidth = 1;
    view.layer.borderColor = [[UIColor colorWithWhite:0.667 alpha:0.8] CGColor];
}

- (UILabel *)getLeftLabel:(NSString *)text {
    UILabel *leftLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, LeftItemWidth, 21)];
    leftLabel.text = text;
    leftLabel.textAlignment = NSTextAlignmentCenter;
    leftLabel.font = [UIFont boldSystemFontOfSize:17.0];
    return leftLabel;
}

- (UIImageView *)getHorizontalLine:(CGFloat)top {
    UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, top, CellWidth, 1)];
    line.backgroundColor = [UIColor lightGrayColor];
    line.alpha = 0.8;
    return line;
}

- (void)msgSwitchValueChanged:(id)sender {
    
    CGFloat hideTop;
    CGFloat selectedViewHeight;
    CGFloat bottomViewChange;
    
    if (_msgSwitch.on == YES) {
        hideTop = CellHeight*2;
        selectedViewHeight = CellHeight*4;
        bottomViewChange = CellHeight*2;
    } else {
        hideTop = CellHeight;
        selectedViewHeight = CellHeight*2;
        bottomViewChange = -CellHeight*2;
    }
    [UIView beginAnimations:@"move" context:nil];
    [UIView setAnimationDuration:0.2];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animatedStop:)];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    _hideView.top = hideTop;
    _selectView.height = selectedViewHeight;
    _bottomView.top += bottomViewChange;
    [UIView commitAnimations];
    
}

- (void)animatedStop:(id)sender {
    NSLog(@"stop ...");
//    _contentView.contentSize = CGSizeMake(AppWidth, _bottomView.bottom+TopPadding);
}

#pragma mark - Keyboard Notification

- (void)addKeyboardNotification {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChange:) name:UIKeyboardWillChangeFrameNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}

- (void)keyboardWillHide:(NSNotification *)notification {
    NSDictionary* userInfo = [notification userInfo];
    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];
    [self moveContentViewWithKeyboardHeght:0.0f withDuration:animationDuration];
}

- (void)keyboardWillChange:(NSNotification *)notification {
    NSDictionary *userInfo = [notification userInfo];
    
    NSValue* aValue = [userInfo objectForKey:UIKeyboardFrameEndUserInfoKey];
    CGRect keyboardRect = [aValue CGRectValue];
    NSValue *animationDurationValue = [userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey];
    NSTimeInterval animationDuration;
    [animationDurationValue getValue:&animationDuration];
    [self moveContentViewWithKeyboardHeght:(CurrentDeviceISiPad ? keyboardRect.size.width : keyboardRect.size.height) withDuration:animationDuration];
}

- (void)moveContentViewWithKeyboardHeght:(CGFloat)height
                            withDuration:(NSTimeInterval)animationDuration {
    keyboardHeight = height;
    CGFloat newHeight = AppHeight - SystemTakeHeight - height;
    if (_contentView.height == newHeight) {
        return;
    }
    
    [UIView beginAnimations:@"moveContentView" context:nil];
    [UIView setAnimationDuration:animationDuration];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    _contentView.height = AppHeight - SystemTakeHeight - height;
    _keyboardBtn.top = AppHeight-SystemTakeHeight-23-5 - height;
    [UIView commitAnimations];
}

- (void)updateStatusAndDate {
    //TODO: set timeview's timedate
    if (scheduleInfo == nil) {
        NSDate *startDate = [NSDate date];
        
        if (itemDate) {
            NSString *time = [EpointDateUtils convertDate2FormatStr:startDate format:@"HH:mm"];
            NSString *date = [EpointDateUtils convertDate2FormatStr:itemDate format:@"yyyy-MM-dd"];
            NSString *itemDateStr = [NSString stringWithFormat:@"%@ %@", date, time];
            startDate = [EpointDateUtils convertString2YMDHMDate:itemDateStr];
        }
        
        _startTime.timeDate = startDate;
        
        NSTimeInterval startTimeInter = [startDate timeIntervalSince1970];
        NSTimeInterval endTimeInter = startTimeInter + 60*60;
        _endTime.timeDate = [NSDate dateWithTimeIntervalSince1970:endTimeInter];
        
        NSTimeInterval sendTimeInter = startTimeInter - 30*60;
        _sendTime.timeDate = [NSDate dateWithTimeIntervalSince1970:sendTimeInter];
    } else {
        NSDate *startTime = [EpointDateUtils convertString2YMDHMDate:scheduleInfo.FromDateTime];
        _startTime.timeDate = startTime;
        _endTime.timeDate = [EpointDateUtils convertString2YMDHMDate:scheduleInfo.ToDateTime];
        NSString *sendTime = scheduleInfo.SendTime;
        if ([EpointStringUtil stringIsNotNull:sendTime]) {
            _sendTime.timeDate = [EpointDateUtils convertStr2Date:sendTime format:@"yyyy/M/d H:mm:ss"];
        } else {
            NSTimeInterval startTimeInter = [startTime timeIntervalSince1970];
            NSTimeInterval sendTimeInter = startTimeInter - 30*60;
            _sendTime.timeDate = [NSDate dateWithTimeIntervalSince1970:sendTimeInter];
        }
        
        _SubjectTF.text = scheduleInfo.Subject;
        _addressTF.text = scheduleInfo.Location;
        _importCtrl.selectedSegmentIndex = [scheduleInfo.Importance intValue];
        _msgSwitch.on = [scheduleInfo.IFNotice isEqualToString:@"1"];
        
        if (_msgSwitch.on) {
            [self msgSwitchValueChanged:_msgSwitch];
        }
        
        _textView.text = scheduleInfo.ActivityDescription;
    }
}

#pragma mark - PGTimeViewDelegate

- (void)timeViewPressed:(PGTimeView *)timeView {
    NSLog(@"timeView tag:%d", timeView.tag);
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:_startTime forKey:@"StartTime"];
    [params setObject:_endTime forKey:@"EndTime"];
    [params setObject:_sendTime forKey:@"SendTime"];
    [params setObject:_msgSwitch.on?@"1":@"0" forKey:@"msgSwitchOn"];
    [params setObject:[NSString stringWithFormat:@"%d", timeView.tag] forKey:@"timeViewTag"];
    SelectedDateViewController *dateCtrl = [[SelectedDateViewController alloc] initWithParams:params];
    [self.navigationController pushViewController:dateCtrl animated:YES];
}

#pragma mark - UITextFieldDelegate

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (!CurrentDeviceISiPad) {
        _keyboardBtn.hidden = YES;
    }
    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

#pragma mark - UITextViewDelegate

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
    if (!CurrentDeviceISiPad) {
        [self setKeyboardBtnHidden:NO];
        CGFloat offSetY = _contentView.contentSize.height-(_contentView.height-(keyboardHeight==0?216:0));
        [_contentView setContentOffset:CGPointMake(0, offSetY) animated:YES];
    }
    return YES;
}

#pragma mark - 

- (void)refreshUIWithThreadGuid:(int)taskId andData:(NSObject *)obj {
    NSMutableArray *arr = (NSMutableArray*)obj;
    if (![[arr objectAtIndex:0]isEqualToString:@"1"]) {
        [self toastMessage:[arr objectAtIndex:1]];
        return;
    }
    
    if (taskId == ScheduleAddTaskId || taskId == ScheduleUpdateTaskId) {
        [self toastMessage:[arr lastObject]];
        [_parentCtrl getData];
        [self.navigationController popViewControllerAnimated:YES];
    }
}

@end
